<?php
include('../conf.php');
$function = $_REQUEST['function'];

if($function=="getNewDataVersion"){
	$comp_id = $_REQUEST['comp_id'];
	$last_update = $_REQUEST['last_update'];
	
	//count record
	$sql = "select count(*) as jml from tb_data_version";
	$conn->SetFetchMode(ADODB_FETCH_ASSOC);
	$rs = $conn->Execute($sql);
	$data = $rs->GetRows();
	
	$sql = "select ver_name,ver_id,ver_transaction from tb_data_version where comp_id=? order by ver_id limit ".$last_update.",".$data[0]['jml'];
	$conn->SetFetchMode(ADODB_FETCH_ASSOC);
	$rs = $conn->Execute($sql, array($comp_id));
	$data = $rs->GetRows();
	echo json_encode($data);
} else if ($function=="getDataVersion") {
	$comp_id = $_REQUEST['comp_id'];
	$from_version = $_REQUEST['from_version'];
	$end_version = $_REQUEST['end_version'];
	$sql = "select * from tb_version where comp_id=? order by ver_id desc limit ".$from_version.", ".$end_version;
	$conn->SetFetchMode(ADODB_FETCH_ASSOC);
	$rs = $conn->Execute($sql, array($comp_id));
	$data = $rs->GetRows();
	echo json_encode($data);
}
?>